package Chapter4;

import java.text.DecimalFormat;
//90页程序4.5
class Circle{
    static double PI = 3.14159265;  //定义全局变量PI
    private int radius; //定义变量半径
    public double circumference(){
        return 2*PI*radius;
    }
    public void setRadius(int r){
        radius = r;
    }
}
public class CircumferenceTester {  //计算圆周长
    public static void main(String[] args) {
        Circle c1 = new Circle();
        c1.setRadius(50);
        Circle c2 = new Circle();
        c2.setRadius(10);
        double circum1 = c1.circumference();
        double circum2 = c2.circumference();
        DecimalFormat fmt = new DecimalFormat("0.###");
        System.out.println("c1的圆周长约为："+fmt.format(circum1));
        System.out.println("c2的圆周长约为："+fmt.format(circum2));
    }
}
